﻿using System;
using System.Data.SqlServerCe;
using RFMobile.Database;

namespace RFMobile.Machines
{
    public class MachineData
    {
        private Int32 _comtec_id_machine;
        private Int32 _comtec_id_mainteiner;
        private Int32 _comtec_id_owner;
        private Int32 _comtec_id_configman;
        private String _tag_id_machine;
        private String _cod_mainteiner;
        private String _cod_owner;
        private String _brand;
        private String _model;
        private String _year;
        private String _notes;
        private DateTime _date_instalation;
        private DateTime _date_next_maintenance;
        private Int32 _status_reg;

        public MachineData(Int32 id)
        {
            _comtec_id_machine = id;
            DatabaseManager db = new DatabaseManager();
            string query_str = "SELECT * FROM machines WHERE comtec_id_machine = " + _comtec_id_machine.ToString();
            try
            {
                if (db.Query(query_str))
                {
                    SqlCeDataReader dr = db.Command.ExecuteReader();
                    if (dr.Read())
                    {
                        _comtec_id_mainteiner = Convert.ToInt32(dr["comtec_id_mainteiner"]);
                        _comtec_id_owner = Convert.ToInt32(dr["comtec_id_owner"]);
                        _comtec_id_configman = Convert.ToInt32(dr["comtec_id_configman"]);
                        _tag_id_machine = dr["tag_id_machine"].ToString();
                        _cod_mainteiner = dr["cod_mainteiner"].ToString();
                        _cod_owner = dr["cod_owner"].ToString();
                        _brand = dr["brand"].ToString();
                        _model = dr["model"].ToString();
                        _year = dr["year"].ToString();
                        _notes = dr["notes"].ToString();
                        _date_instalation = Convert.ToDateTime(dr["date_instalation"]);
                        _date_next_maintenance = Convert.ToDateTime(dr["date_next_maintenance"]);
                        _status_reg = Convert.ToInt32(dr["status_reg"]);
                    }
                    dr = null;
                }
                db = null;
            }
            catch (SqlCeException ex)
            {
               // Log error...
            }
        }

        public Int32 comtec_id_machine
        {
            get
            {
                return (_comtec_id_machine);
            }
        }

        public String cod_mainteiner
        {
            get
            {
                return (_cod_mainteiner);
            }
        }

        public DateTime date_next_maintenance
        {
            get
            {
                return (_date_next_maintenance);
            }
            set
            {
                _date_next_maintenance = value;
            }
        }
    }
}
